package online.shenjian.kafka;

import lombok.Data;

@Data
public class CustomerAnalysis {

  private String customerId;
  private Double totalSpending;
  private Double avgSpending;
  private Double maxSpending;

  public CustomerAnalysis() {}

  public CustomerAnalysis(Double totalSpending, Double avgSpending) {
    this.totalSpending = totalSpending;
    this.avgSpending = avgSpending;
  }

  public CustomerAnalysis(String customerId, Double totalSpending, Double avgSpending, Double maxSpending) {
    this.customerId = customerId;
    this.totalSpending = totalSpending;
    this.avgSpending = avgSpending;
    this.maxSpending = maxSpending;
  }

  public CustomerAnalysis withMax(Double maxSpending) {
    return new CustomerAnalysis(customerId, totalSpending, avgSpending, maxSpending);
  }

  public CustomerAnalysis normalize(String customerId) {
    Double total = getTotalSpending();
    Double avg = getAvgSpending();
    Double max = getMaxSpending();
    if (total == 0 || avg == 0 || max == 0) {
      return this;
    }
    return new CustomerAnalysis(customerId, total, avg, max);
  }
}